package com.forlove.app.qselect.login.entity;

/**
 * Created by yjl on 2017/10/18.
 */

import com.forlove.app.common.base.mvp.entity.BaseEntity;
import com.forlove.app.common.base.serializer.JSONKey;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


/**
 * Created by yx on 2016/1/21.
 */
public class UserListEntity extends BaseEntity {
    /**
     *
     */
    private static final long serialVersionUID = 1567031489288750321L;

    /**
     * 登录用户的信息目录
     */
    @JSONKey(keys = "user_list", type = JSONArray.class)
    public JSONArray mUserList;

    /**
     * 最新用户的user_id
     */
    @JSONKey(keys = "user_id", type = Integer.class)
    public int mUserID; // 用户id;

    @Override
    public JSONObject serializeToJSONObject() {
        JSONObject json = new JSONObject();
        if (mUserList == null) {
            mUserList = new JSONArray();
        }
        try {
            json.put("user_id", this.mUserID);
            json.put("user_list", this.mUserList);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return json;
    }

    @Override
    public String serializeToString() {
        return serializeToJSONObject().toString();
    }

    @Override
    public void parseJSONObject(JSONObject jsonObj) {
        if (jsonObj == null) {
            return;
        }
        try {
            if (jsonObj.has("user_list")) {
                if (mUserList == null) {
                    mUserList = new JSONArray();
                }
                this.mUserList = jsonObj.getJSONArray("user_list");
            }
            if (jsonObj.has("user_id")) {
                this.mUserID = jsonObj.getInt("user_id");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

